package com.bins.springboot.dubbo.api.thread;

import io.netty.util.concurrent.CompleteFuture;

import java.util.concurrent.*;

public class Test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Shop shop = new Shop();
        ExecutorService e = Executors.newWorkStealingPool(2000);
//        Future<?> submit = null;
//        for (int i = 0; i < 1000000; i++) {
//            submit = e.submit(shop::get);
//
//        }

            CompletableFuture.supplyAsync(() -> {
                shop.get1();
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
                System.out.println("hello ");
                return "hello world";

            }, e).whenComplete((s, t) -> {
                System.out.println(s);

                System.out.println(t.getMessage());
            }).join();

//        Future<Integer> future = e.submit(() -> {
//            for (int i = 0; i < 100; i++) {
//                shop.buy1();
//            }
//            return 1;
//        });

            //submit.get();
//            e.shutdown();
//
//            if(e.isTerminated())
            System.out.println(shop.getGoods());
//        e.shutdown();
//        while (true){
//            if(e.isTerminated()){
//                System.out.println(shop.getGoods());
//                break;
//            }
//        }

    }
}
